package com.us.usws.support.listener;

import javax.inject.Singleton;

import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
import com.google.inject.struts2.Struts2GuicePluginModule;
import com.us.usws.support.ext.GuiceInjectorFactory;

/**
 * custom listener
 * 
 */
public class SiteGuiceStruts2Listener extends GuiceServletContextListener {

	@Override
	public Injector getInjector() {
		//main injected module
		Injector injector = GuiceInjectorFactory.getInjector();

		//append struts2
		injector.createChildInjector(new Struts2GuicePluginModule(), new ServletModule() {
			@Override
			protected void configureServlets() {
				// Struts 2 setup
				bind(StrutsPrepareAndExecuteFilter.class).in(Singleton.class);
				filter("*.action").through(StrutsPrepareAndExecuteFilter.class);
				filter("*.jsp").through(StrutsPrepareAndExecuteFilter.class);

			}
		});

		return injector;
	}

}
